/* 
 * Copyright (c) 2002, Cameron Zemek
 * 
 * This file is part of JGrid.
 * 
 * JGrid is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * JGrid is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */
package net.sf.jeppers.grid;

import java.io.Serializable;

/**
 * Default implementation of <code>SelectionModel</code>.
 * 
 * @author <a href="grom@capsicumcorp.com">Cameron Zemek</a>
 */
public class DefaultSelectionModel extends AbstractSelectionModel implements Serializable {
	private int anchorRow;
	private int anchorColumn;
	private int leadRow;
	private int leadColumn;

	private int firstSelectedRow;
	private int firstSelectedColumn;
	private int lastSelectedRow;
	private int lastSelectedColumn;

	public DefaultSelectionModel() {
		clearSelection();
	}

	public boolean isSelected(int row, int column) {
		return (
			(row >= firstSelectedRow && row <= lastSelectedRow)
				&& (column >= firstSelectedColumn
					&& column <= lastSelectedColumn));
	}

	public void setAnchor(int row, int column) {
		anchorRow = row;
		anchorColumn = column;
		fireSelectionChanged();
	}

	public void setLead(int row, int column) {
		leadRow = row;
		leadColumn = column;
		fireSelectionChanged();
	}

	public void clearSelection() {
		anchorRow = -1;
		anchorColumn = -1;
		leadRow = -1;
		leadColumn = -1;
		firstSelectedRow = lastSelectedRow = -1;
		firstSelectedColumn = lastSelectedColumn = -1;
	}

	public int getAnchorRow() {
		return anchorRow;
	}

	public int getAnchorColumn() {
		return anchorColumn;
	}

	public int getLeadRow() {
		return leadRow;
	}

	public int getLeadColumn() {
		return leadColumn;
	}

	public int getFirstSelectedColumn() {
		return firstSelectedColumn;
	}

	public int getLastSelectedColumn() {
		return lastSelectedColumn;
	}

	public int getFirstSelectedRow() {
		return firstSelectedRow;
	}

	public int getLastSelectedRow() {
		return lastSelectedRow;
	}

	public void setSelectionRange(int topRow, int leftColumn, int bottomRow, int rightColumn){
		firstSelectedRow = topRow;
		lastSelectedRow = bottomRow;
		firstSelectedColumn = leftColumn;
		lastSelectedColumn = rightColumn;
	}
}
